﻿//-------------------------------------------------------------------------------------------------------------------------------------
// Copyright (C) 2005 greatelsoft.com All Rights Reserved
//-------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Data.Common;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Web.UI;
using GTS.Channel.Api.Entity;
using Pub.Class;
using GTS.Channel.Api.Helper;

namespace GTS.Channel.Api {
    /// <summary>
    /// 九易SMS和IVR的MO MT MR接收数据接口
    /// </summary>
    public class HongLian : ISMSIVR {
        /// <summary>
        /// SPCode
        /// </summary>
        public string SPCode = "HongLian";
        /// <summary>
        /// SMS MO的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMOData() {
            //初始值
             return null;
        }
        /// <summary>
        /// SMS MT的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMTData() {
            return null;
        }
        /// <summary>
        /// SMS MR的参数数据
        /// </summary>
        /// <returns></returns>
        public ChannelDealData GetSMSMRData() {
            ChannelDealData info = new ChannelDealData();
            info.SPCode = SPCode;

            //接收值
            info.LinkID = Request2.GetQ("linkid").Trim();
            info.Mobile = Request2.GetQ("phone").Trim();
            info.LongPhone = Request2.GetQ("spnumber").Trim();
            string query = Request2.GetQ("serviceid").Trim();
            info.ResponseStatus = Request2.GetQ("msgstatus") == "DELIVRD" ? 1 : 0;
            //info.ReceiveQuery = Request2.GetQ("serviceid").Trim();// 1;
            info.MRDate = DateTime.Now;
            
            // 修改他们的id变成指令
            if (query == "hycb02" && info.LongPhone == "10629500")
                info.ReceiveQuery = "81052";
            else if (query == "hyms02" && info.LongPhone == "10629500102")
                info.ReceiveQuery = "A02";
            else if (query == "ZHHD02" && info.LongPhone == "106295004")
                info.ReceiveQuery = "4C";
            else if (query == "BKDG01" && info.LongPhone == "10629500")
                info.ReceiveQuery = "BK01";
            else
                info.ReceiveQuery = "";

            if (info.Mobile.IsNullEmpty() || info.LinkID.IsNullEmpty() || info.LongPhone.IsNullEmpty()) return null;

            string[] infos = info.ReceiveQuery.Split('_');
            if (infos.Length >= 4) {
                info.MountCode = infos[1].ToInt();
                info.GameCode = infos[2].PadLeft(5, '0');
                info.ChargeCode = infos[3];
            } else {
                info.MountCode = 493;
                info.GameCode = "00999";
                info.ChargeCode = "9";
            }

            //如果数据库中存在价格以数据库里为主
            ChannelInfo extInfo = Base.GetChannelInfo(SPCode, info.LongPhone, info.ReceiveQuery);
            if (extInfo.IsNotNull() && extInfo.ChannelName.IsNotNull()) {
                info.Price = extInfo.Price.Value;
                info.SMSKey = extInfo.CstCode;
                info.ReceiveQuery = extInfo.Instruction;
            }

            return info;
        }
        /// <summary>
        /// IVR的参数数据
        /// </summary>
        /// <returns></returns>
        public IVRDealData GetIVRMRData() {
            return null;
        }
        /// <summary>
        /// 输出消息
        /// </summary>
        /// <param name="res"></param>
        public void Output(ResultEnum res) {
            Msg.WriteEnd((int)res);
        }
    }
}

